<template>
    <div>
        <div class="content-page">
			<div id="content" class="content">
				<slot />
			</div>
		</div>

        <BottomNavigation 
            :currentRoute="selectedRoute"
            @navigate="onNavigate"
        />
    </div>
</template>

<script setup>
import { ref } from 'vue';
import BottomNavigation from '@/Pages/compontents/BottomNavigation.vue';
import { router,usePage } from '@inertiajs/vue3';
import {onMounted, onUnmounted} from 'vue';
import RouterPath from '@/constans/RouterPath.js';
import request from '@/utils/request';
import apiUrls  from '@/config/apiUrls'; 
onMounted(()=>{
    console.log("加载路由布局")
    getToken()
})

const getToken = async ()=>{
    const response = await request.get(apiUrls.zhjy.getToken);
      if( response.code === 200 ){
        console.log('响应',response);
      }
}

onUnmounted(() => {
  console.log('组件已卸载');
  removeCurrentRouteToStorage()
});


const removeCurrentRouteToStorage = () => {
    localStorage.removeItem('currentRoute');
};

// 定义一个函数来设置当前路由到本地存储
const setCurrentRouteToStorage = (route) => {
    localStorage.setItem('currentRoute', route);
};

// 定义一个函数来从本地存储中获取当前路由
const getCurrentRouteFromStorage = () => {
    return localStorage.getItem('currentRoute') || 'home';
};

const selectedRoute = ref(getCurrentRouteFromStorage()); // 默认是主页
const currentUrl = ref(RouterPath.users.home);
const onNavigate = (route) => {
    selectedRoute.value = route;
    console.log(`导航到: ${route}`);
    const url = `${RouterPath.users.baseUrl}${route}`;
    currentUrl.value = url;
    router.visit(url);
    setCurrentRouteToStorage(route);
};
</script>

<style scoped>
#app {
    font-family: Avenir, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
    margin-top: 60px;
}
</style>    